{extend name="layout"/}

{block name="breadcrumb"}
<h2>{$title}套题</h2>
<ol class="breadcrumb">
    <li><a href="{:url('index/index')}">首页</a></li>
    <li><a href="{:url('lang/index')}">语种列表</a></li>
    <li><strong>{$search.lang}</strong></li>
    <li><strong>{$search.className}</strong></li>
    <li><strong>{$courseName}</strong></li>
    <li><strong>{$title}套题</strong></li>
</ol>
{/block}

{block name="search"}
{include file='lang_class_recite_type/search'/}
{/block}

{block name="main"}

<div class="btn-group margin-bottom-10">
    <button class="btn btn-white" type="button">
        <a href="{:url('lang_class_file/index', ['classId' => $search.classId, 'courseType' => $search.courseType, 'type' => 1, 'lang' => $search.lang, 'className' => $search.className])}" class="inherit">视频列表</a>
    </button>
    <button class="btn btn-white" type="button">
        <a href="{:url('lang_class_file/index', ['classId' => $search.classId, 'courseType' => $search.courseType, 'type' => 2, 'lang' => $search.lang, 'className' => $search.className])}" class="inherit">音频列表</a>
    </button>
    <button class="btn btn-white" type="button">
        <a href="{:url('lang_class_file/index', ['classId' => $search.classId, 'courseType' => $search.courseType, 'type' => 3, 'lang' => $search.lang, 'className' => $search.className])}" class="inherit">课件列表</a>
    </button>
    {if $search.courseType != 1 }
    <button class="btn btn-white" type="button">
        <a href="{:url('lang_class_file/index', ['classId' => $search.classId, 'courseType' => $search.courseType, 'type' => 4, 'lang' => $search.lang, 'className' => $search.className])}" class="inherit">随堂作业</a>
    </button>
    <button class="btn {$search.type == 1 ? 'btn-primary' : 'btn-white'}" type="button">
        <a href="{:url('lang_class_recite_type/index', ['classId' => $search.classId, 'courseType' => $search.courseType, 'type' => 1, 'lang' => $search.lang, 'className' => $search.className])}" class="inherit">背单词</a>
    </button>
    <button class="btn {$search.type == 2 ? 'btn-primary' : 'btn-white'}" type="button">
        <a href="{:url('lang_class_recite_type/index', ['classId' => $search.classId, 'courseType' => $search.courseType, 'type' => 2, 'lang' => $search.lang, 'className' => $search.className])}" class="inherit">背句子</a>
    </button>
    {/if}
</div>

<div class="ibox float-e-margins">
    <div class="ibox-title">
        <h5>{$title}套题</h5>
    </div>
    <div class="ibox-content">
        <p>
            <a href="{:url('form', ['classId' => $search.classId, 'courseType' => $search.courseType, 'type' => $search.type, 'lang' => $search.lang, 'className' => $search.className])}" class="btn btn-primary btn-sm"><i class="fa fa-plus-circle"></i> 添加{$title}套题</a>
            <button class="btn btn-danger btn-sm" onclick="actionAll('{:url("disables", ['status' => 0, 'classId' => $search.classId, 'courseType' => $search.courseType, 'type' => $search.type, 'lang' => $search.lang, 'className' => $search.className])}')">批量禁用</button>
            <button class="btn btn-primary btn-sm" onclick="actionAll('{:url("disables", ['status' => 1, 'classId' => $search.classId, 'courseType' => $search.courseType, 'type' => $search.type, 'lang' => $search.lang, 'className' => $search.className])}')">批量启用</button>
            <button class="btn btn-danger btn-sm" onclick="actionAll('{:url("deletes", ['classId' => $search.classId, 'courseType' => $search.courseType, 'type' => $search.type, 'lang' => $search.lang, 'className' => $search.className])}')">批量删除</button>
        </p>
        <div class="table-responsive table-elem">
            <p>共 {$count} 条数据</p>
            <table class="table table-striped">
                <thead>
                <tr>
                    <th class="checkbox-th">
                        <div class="checkbox checkbox-primary">
                            <input id="checkbox-all" type="checkbox">
                            <label for="checkbox-all"></label>
                        </div>
                    </th>
                    <th>ID</th>
                    <th>名称</th>
                    <th>权重</th>
                    <th>状态</th>
                    <th>创建时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                {foreach $model as $key=>$vo }
                <tr>
                    <td>
                        <div class="checkbox checkbox-primary">
                            <input id="checkbox{$vo.id}" type="checkbox" value="{$vo.id}" class="checkbox-item">
                            <label for="checkbox{$vo.id}"></label>
                        </div>
                    </td>
                    <td>{$vo.id}</td>
                    <td>{$vo.name}</td>
                    <td>{$vo.sort_num}</td>
                    <td>
                        <span class="label {$vo.status == 1 ? 'label-info' : 'label-danger'}">{$vo.statusText}</span>
                    </td>
                    <td>{$vo.create_time}</td>
                    <td>
                        <a href="{:url('form', ['id' => $vo.id, 'classId' => $search.classId, 'courseType' => $search.courseType, 'type' => $search.type, 'lang' => $search.lang, 'className' => $search.className, 'typeId' => $vo.id])}" class="btn btn-success btn-xs">编辑</a>
                        <a href="{:url('lang_class_recite/index', ['classId' => $search.classId, 'courseType' => $search.courseType, 'type' => $search.type, 'lang' => $search.lang, 'className' => $search.className, 'typeId' => $vo.id])}" class="btn btn-success btn-xs">{$title}列表</a>
                        <a href="javascript:void(0);" data-id="{$vo.id}" class="disabled-elem btn btn-warning btn-xs">{$vo.status == 1 ? '禁用' : '启用'}</a>
                        <a href="javascript:void(0);" data-id="{$vo.id}" class="delete-elem btn btn-danger btn-xs">删除</a>
                    </td>
                </tr>
                {/foreach}
                </tbody>
            </table>
            {$model|raw}
        </div>

    </div>
</div>
{/block}

{block name="jsFile"}
<script>
    // 删除操作
    $('.delete-elem').click(function () {
        let id = $(this).data('id');
        let url_tmp = "{:url('delete', ['id' => '__ID__'])}";
        let url = url_tmp.replace('__ID__', id);
        layer.confirm('您确定要删除该数据吗', {}, function () {
            $.ajax({
                url: url,
                data: {
                    classId: "{$search.classId}",
                    courseType: "{$search.courseType}",
                    type: "{$search.type}",
                    lang: "{$search.lang}",
                    className: "{$search.className}"
                },
                type: 'POST',
                success: function (e) {
                    layer.msg('删除成功', {icon: 1});
                    window.location.href = e.data.url;
                },
                error: function () {
                    layer.msg('删除失败', {icon: 2});
                }
            })
        });
    });

    // 修改状态
    $('.disabled-elem').click(function () {
        let id = $(this).data('id');
        let url_tmp = "{:url('disabled', ['id' => '__ID__'])}";
        let url = url_tmp.replace('__ID__', id);
        layer.confirm('您确定要修改该数据状态吗', {}, function () {
            $.ajax({
                url: url,
                data: {
                    classId: "{$search.classId}",
                    courseType: "{$search.courseType}",
                    type: "{$search.type}",
                    lang: "{$search.lang}",
                    className: "{$search.className}"
                },
                type: 'POST',
                success: function (e) {
                    layer.msg('操作成功', {icon: 1});
                    window.location.href = e.data.url;
                },
                error: function () {
                    layer.msg('操作失败', {icon: 2});
                }
            })
        });
    });
</script>
{/block}